import { StorageKey } from '../common/Key';
import { EnergyMgr } from '../component/EnergyMgr';
cc.Class({
    extends: require('BaseScene'),

    properties: {
        nodLogo: cc.Node,
    },

    onLoad() {
        this._super();
    },

    start() {
        G.partner.sendEvent('场景', { '类型': 'boot' });
        this.allStep = 2;
        this.step = 0;
        this.index = 0;
        this._boot();
    },

    _boot() {
        cc.game.setFrameRate(G.config.FPS);
        cc.director.getCollisionManager().enabled = true;
        // cc.director.getCollisionManager().enabledDebugDraw = true;

        EnergyMgr.init();

        this._loadScene();
    },

    _loadJson(cb) {
        G.json.loadAllJsons(() => {
            cb();
        });
        // G.json.addItem('test1');
        // G.json.addItem('test2');
        // G.json.startLoad(() => {
        //     console.log(G.json.getJson('test2'))
        //     cb();
        // });
    },

    _preloadScene() {
        G.game.preloadScene('SceneHome', null, () => {
            this.step++;
            this._loadScene();
        });
        G.game.preloadScene('SceneGame', null, () => {
            this.step++;
            this._loadScene();
        });
    },

    _loadScene() {
        if (this.step >= this.allStep || true) {
            cc.tween(this.nodLogo)
                .delay(1)
                .to(1, { opacity: 0 })
                .call(() => {
                    G.data.setItem(StorageKey.FIRST_LAUNCH, true);
                    G.game.loadScene('SceneHome');
                })
                .start();
        }
    },
});
